<?php

class EditionsController extends Zend_Controller_Action{
    public function init(){

    }

    public function indexAction(){
        $filterEditions = new Application_Form_FilterEdition();
        $filterEditions->isValid($this->getRequest()->getParams());

        $editionsPaginator = Application_Model_Editions::getInstance()
            ->getPaginatorForFilter($filterEditions->getValues());
        $editionsPaginator->setItemCountPerPage(12);
        $page = $this->getRequest()->getParam('page');
        if(!is_null($page)){
            $editionsPaginator->setCurrentPageNumber($page);
        }
        $this->view->filterEditions = $filterEditions;
        $this->view->filterParams = $this->getRequest()->getParams();
        $this->view->editionsPaginator = $editionsPaginator;
    }

    public function addAction(){
        $formEdition = new Application_Form_Edition();
        $request = $this->getRequest();
        if($request->isPost()){
            if($formEdition->isValid($request->getPost())){
                Application_Model_Editions::getInstance()->create($formEdition->getValues());
                $this->redirect($this->view->url(array('controller' => 'editions'), null, true));
            }
        }
        $this->view->formEdition = $formEdition;
    }
}